$(function() {
    $('.layui-plus').click(function() {
        layer_iframe('添加发送红包', 'edit');
    });
    window.page = 1;
    window.limit = 10;
    window.options = {
        id: 'data_table',
        elem: '.layui-table.data-table',
        url: location.pathname + location.search,
        where: {},
        page: {
            curr: 1
        },
        limits: [10, 25, 50, 100],
        done: function(res, curr, first) {
            if (!res.data && curr > 1) {
                window.options.page.curr = curr - 1;
                window.tableIns.reload(window.options);
            }
            window.options.page.curr = curr;
            window.page = curr;
            window.limit = res.limit;
        },
        cols: [
            [{
                field: 'user_id',
                title: '发布人编号',
                unresize: true,
                align: 'center',
                templet:function(d){
                    return '<div style="cursor:pointer;text-decoration:underline;color:#6590DC" lay-event="user" >'+d.number+'</div>';
                },
                width:'8%'
            }, {
                field: 'num',
                title: '红包数量',
                unresize: true,
                align: 'center',
                width:'8%',
                
            }, {
                field: 'get_num',
                title: '剩余数量',
                unresize: true,
                align: 'center',
                width:'8%',
              
            }, {
                field: 'price',
                title: '红包金额',
                unresize: true,
                align: 'center',
                 width:'8%',
                 
            }, {
                field: 'odd_price',
                title: '剩余金额',
                unresize: true,
                align: 'center',
                 width:'8%',
                 
            }, {
                field: 'jump',
                title: '跳转类型',
                unresize: true,
                align: 'center',
                templet:function(d){
                    switch(d.jump){
                        case 1: return '服务';break;
                        case 2: return '需求';break;
                        case 3: return '个人主页';break;
                    }
                } ,width:'8%'
            }, {
                field: 'pay_type',
                title: '支付方式',
                unresize: true,
                align: 'center',
                templet:function(d){
                    switch(d.pay_type){
                        case 0: return '余额';break;
                        case 1: return '微信';break;
                        case 2: return '支付宝';break;
                        
                    }
                },
                width:'10%'
            }, {
                field: 'pay_time',
                title: '支付时间',
                unresize: true,
                align: 'center',
                 width:'12%'
            },{
                field: 'order_no',
                title: '内部订单号',
                unresize: true,
                align: 'center',
                 width:'16%'
            }, {
                field: 'pay_status',
                title: '状态',
                unresize: true,
                align: 'center',
                templet:function(d){
                    if(d.pay_status == 1){
                        return '<span style="color:#6590DC">正常</span>';
                    }else if(d.pay_status == 2){
                        return '<span style="color:#E7DB74">已过期</span>';
                    }else{
                        return '<span style="color:#AE2824">已领完</span>'
                    }
                },
                 width:'8%'
            },{
                title: '操作',
                unresize: true,
                align: 'center',
                toolbar: '#toolbar_normal',
                width:'12%'
            }]
        ],
    };
    window.tableIns = laytable.render(window.options);
    laytable.on('tool(data_table)', function(obj) {
        if (obj.event === 'edit') {
            layer_iframe('编辑发送红包', 'edit?id=' + obj.data.id);
        } else if (obj.event === 'del') {
            _ajax_remove('确定删除该发送红包吗?', 'before_red_packet', obj.data.id);
        }else if (obj.event === 'user') {
            layer_iframe('会员信息', '/before/user/index?id=' + obj.data.user_id);

        }else if (obj.event === 'get') {
            layer_iframe('红包领取记录', '/before/red_packet_get/index?foreign_key=' + obj.data.id);

        }
    });
});
